using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_Controls_AdminMenu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetChildren(0, Menu1);
        }
       
    }


    private void GetChildren(int ParentId, Menu menu)
    {

        DataSet MenuDS = new DataSet();
        MenuDS = DD.Data.SQL.AdminMenuController.GetActiveMenus(ParentId);
        if (MenuDS.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in MenuDS.Tables[0].Rows)
            {
                MenuItem item = new MenuItem();
                item.Text = dr["MENU_NAME"].ToString();
                item.NavigateUrl = ResolveUrl("~/admin/?id=" + Convert.ToInt32(dr["ID"]));
                menu.Items.Add(item);
                int PID = Convert.ToInt32(dr["ID"]);
                GetChildren(PID, item);
            }
        }
    }

    private void GetChildren(int ParentId, MenuItem menu)
    {

        DataSet MenuDS = new DataSet();
        MenuDS = DD.Data.SQL.AdminMenuController.GetActiveMenus(ParentId);
        if (MenuDS.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in MenuDS.Tables[0].Rows)
            {
                MenuItem item = new MenuItem();
                item.Text = dr["MENU_NAME"].ToString();
                item.NavigateUrl = ResolveUrl("~/admin/?id=" + Convert.ToInt32(dr["ID"]));
                menu.ChildItems.Add(item);

                int PID = Convert.ToInt32(dr["ID"]);
                GetChildren(PID, item);
            }
        }
    }
  
}
